package pers.mobian.springfifth;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pers.mobian.springseventh.MoBian;

/**
 * @Date 2021/7/14 20:13
 * @Created mobian
 * @Description
 */
public class BianChengShiSpringTest2 {
	public static void main(String[] args) {


		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigBean.class);
		AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext(ConfigBean2.class);
		// 构建父子容器
		context.setParent(context);

		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinition.setBeanClass(Teacher.class);

		AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinition2.setBeanClass(MoBian.class);
		// 构建父子Bean
		beanDefinition2.setParentName("teacher");

		context.registerBeanDefinition("teacher",beanDefinition);
		context.registerBeanDefinition("mobian",beanDefinition2);
		System.out.println(context.getBean("teacher"));
		System.out.println(context.getBean("mobian"));

	}
}
